﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Linq;
using NHibernate.Engine;
using DeStores.Common.DAL.Abstract;

namespace DeStores.Common.DAL.Manager
{
    public class Repository : IRepository
    {
        #region Members

        private readonly ISession _session;

        #endregion

        #region Constructors

        public Repository(ISession session)
        {
            this._session = session;
        }

        #endregion

        #region IRepository Members

        public T Insert<T>(T obj)
        {
            using (var t = _session.BeginTransaction())
            {
                _session.Save(obj);
                t.Commit();
                return obj;
            }
        }

        public T Update<T>(T obj)
        {
            throw new NotImplementedException();
        }

        public void Delete<T>(T obj)
        {
            throw new NotImplementedException();
        }

        public IQueryable<T> Query<T>()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            this._session.Dispose();
        }

        #endregion
    }
}
